resToTarget = function (resId, type) {
    if (type === 1) {
        window.open('/poetry/' + resId)
    } else if (type === 2) {
        window.open('/author/' + resId)
    }
}

doCollection = function (colId) {
    var spNode = document.getElementById('sp_' + colId)
    let token = getToken();
    if (spNode.classList.contains('collect-cancel')) {
        axios({
            url: '/api/collection/' + colId,
            method: "delete",
            headers: {'Authorization': token},
        }).then(function (response) {
            if (response.data.code === 200) {
                spNode.classList.remove('collect-cancel')
                spNode.classList.add('collect-add')
            } else {
                Qmsg.error(response.data.msg)
            }
        }).catch(function (error) {
            console.log(error);
            Qmsg.error("未知错误")
        });
    } else {
        axios({
            url: '/api/collection/' + colId,
            method: "post",
            headers: {'Authorization': token},
        }).then(function (response) {
            if (response.data.code === 200) {
                spNode.classList.remove('collect-add')
                spNode.classList.add('collect-cancel')
            } else {
                Qmsg.error(response.data.msg)
            }
        }).catch(function (error) {
            console.log(error);
            Qmsg.error("未知错误")
        });
    }
}
